
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using GruntXProductions;
using Viper;
using Viper.Opcodes;

namespace Diamond
{
	public partial class CodeGen 
	{
		public void GetBooleanValue(Expression exp)
		{
			if(GuessType(exp) == VType.Dword)
					ParseArthemeticExpression(exp);
			else if(GuessType(exp) == VType.String)
					ParseStringExpression(exp);
		}
		public void ParseBooleanExpression(Expression exp)
		{
			foreach(SyntaxNode sn in exp.Items)
			{
				if(sn is Operator)	
				{
					Operator op = sn as Operator;
					if(isOverloaded(op,"boolean"))
					{
						CallOperator(op, getOverload(op, "boolean"));
						
					}
					else if(sn is And)
					{
						ParseBooleanExpression((Expression)op.Op1);
						ParseBooleanExpression((Expression)op.Op2);
						Assembler.Emit(new and());
						
					}
					else
					{
						GetBooleanValue((Expression)op.Op1);
						GetBooleanValue((Expression)op.Op2);
						if(sn is Equal)
						{
							if(GuessType(op.Op1) == VType.Dword)
							{
								Assembler.Emit(new teq());
							}
						}
						else if(sn is NotEqual)
						{
							if(GuessType(op.Op1) == VType.Dword)
							{
								Assembler.Emit(new tne());
							}
						}
						else if(sn is GreaterThan)
						{
							if(GuessType(op.Op1) == VType.Dword)
							{
								Assembler.Emit(new tgt());
							}
						}
						else if(sn is LessThan)
						{
							if(GuessType(op.Op1) == VType.Dword)
							{
								Assembler.Emit(new tlt());
							}
						}
					}
				}
			}
		}
		
	}
	
}